﻿using Enterprise_Set.API.Application.Commands.Week1.Log_CR;
using Enterprise_Set.API.Application.Commands.Week1.Process_CRUD;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Controllers.Week1
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        public ProcessController(IMediator mediator, ILogger<ProcessController> logger)
        {
            this.mediator = mediator;
            Logger = logger;
        }

        public IMediator mediator { get; set; }
        public ILogger<ProcessController> Logger { get; set; }
        /// <summary>
        /// 显示工作中心表数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("GetWorkCenterData")]
        public async Task<Result> GetWorkCenterData()
        {
            try
            {
                Logger.LogInformation("显示工作中心成功");
                return await mediator.Send(new GetWorkCenterCommand());
            }
            catch (Exception ex)
            {
                Logger.LogError("显示工作中心失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 获取资源中心资源表数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("GetWorkCenterWealthData")]
        public async Task<Result> GetWorkCenterWealthData(GetWOrkCenterWealthCommand cmd)
        {
            try
            {
                Logger.LogInformation("显示工作中心资源表成功");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                Logger.LogError("显示工作中心资源表失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 添加工序表数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("AddProcessData")]
        public async Task<Result> AddProcessData(AddProcessCommand cmd)
        {
            try
            {
                Logger.LogInformation("添加工序表成功");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                Logger.LogError("添加工序表失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 显示工作中心表数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("ShowProcessData")]
        public async Task<Result> ShowProcessData()
        {
            try
            {
                Logger.LogInformation("显示工作中心成功");
                return await mediator.Send(new ShowProcessCommand());
            }
            catch (Exception ex)
            {
                Logger.LogError("显示工作中心失败" + ex.Message);
                throw;
            }
        }
    }
}
